package ThreadDemo;

/**
 * @author:周鹏
 * @date: 2020/11/10 14:20
 * @description:模拟多线程抢票
 */
public class TicketDemo implements Runnable{

    private  int ticket=10;
    @Override
    public void run() {
          while(true){
            if (ticket<=0){
                break;
            }else {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"获取了第："+ticket--+"张票");

            }

        }
    }

    public static void main(String[] args) {
        TicketDemo tickerDemo=new TicketDemo();
        new Thread(tickerDemo,"顾客一").start();
        new Thread(tickerDemo,"黄牛党1").start();
        new Thread(tickerDemo,"顾客2").start();


    }

}
